<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="生产品项" prop="scpx">
        <el-input v-model="queryParams.scpx" placeholder="请输入生产品项" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="测试时间" prop="cssj">
        <el-date-picker  :editable="false"
          clearable
          size="small"
          v-model="queryParams.cssj"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择测试时间"
        >
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['Productionline_torque_main:torque_main:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['Productionline_torque_main:torque_main:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['Productionline_torque_main:torque_main:remove']">删除</el-button>
      </el-col>
      <!--  <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['Productionline_torque_main:torque_main:export']"
          >导出</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-s-check" size="mini" :disabled="multiple" @click="handleCheck"
          v-hasPermi="['Productionline_torque_main:torque_main:check']">审核</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="torque_mainList" @selection-change="handleSelectionChange" max-height="550">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" width="100px" />
      <el-table-column label="检测日期" align="center" prop="syrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.syrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产日期" align="center" prop="scrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.scrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产品项" align="center" prop="scpx" width="280" />
      <!-- <el-table-column label="测试时间" align="center" prop="cssj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cssj, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="瓶坯厂商" align="center" prop="pcj" />
      <el-table-column label="瓶盖厂商" align="center" prop="gcs" /> -->
      <!-- <el-table-column label="检测项目" align="center" prop="jcxm" /> -->
      <!-- <el-table-column label="品控员" align="center" prop="pky" /> -->

      <!--      <el-table-column
        label="报表编号"
        align="center"
        prop="bbbh"
        width="200px"
      />-->
      <el-table-column label="审核人" align="center" prop="shrperson" />
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="250px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="excelhandleView(scope.row)">导出</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['Productionline_torque_main:torque_main:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['Productionline_torque_main:torque_main:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改瓶装水扭矩测试记录对话框 -->

    <el-dialog v-myFullscreen :title="title" :visible.sync="open" width="900px" append-to-body custom-class="myDialog"
      fullscreen>
      <TableHeader @nameChange="nameChange" :data="{
          mainTitle: '瓶装水扭矩测试记录',
          company: '青岛崂山矿泉水有限公司',
          code: form.bbbh,
        }" />
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="检测日期" prop="syrq">
              <el-date-picker :editable="false" clearable size="small" v-model="form.syrq" type="date"
                value-format="yyyy-MM-dd" placeholder="选择检测日期" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产日期" prop="scrq">
              <el-date-picker :editable="false" clearable size="small" v-model="form.scrq" type="date"
                value-format="yyyy-MM-dd" placeholder="选择生产日期" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--  <el-select v-model="form.scpx" placeholder="请选择品项" :disabled="openDisabled">
                <el-option
                  v-for="dict in px"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select> -->
            <el-form-item label="生产品项" prop="scpx">
              <template slot-scope="scope">
                <Dialog @dialogChange="dialogChange($event, scope)" :echoValue="form.scpx" parameter="rows" value="id"
                  label="name" :multiple="false" search="name/code" url="/basic/productInfo/listSelect"
                  :column="['产成品编号/code', '产成品名称/name']" :axiosData="{ typeCode: ccpType }" placeholder="请选择内容" />
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="测试时间" prop="cssj">
              <!-- <el-date-picker  :editable="false"
                clearable
                size="small"
                v-model="form.cssj"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择测试时间"
                :disabled="openDisabled"
              >
              </el-date-picker> -->
              <el-time-picker :editable="false" clearable v-model="form.cssj" type="time" format="HH:mm"
                value-format="HH:mm" placeholder="选择测试时间" :disabled="openDisabled">
              </el-time-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="瓶坯厂商" prop="pcj">
              <!-- <el-input
                v-model="form.pcj"
                placeholder="请输入胚厂商"
                :disabled="openDisabled"
              /> -->
              <!-- <ReportDialog
                @dialogChange="form.pcj = $event.value"
                :echoValue="form.pcj"
                value="id"
                label="label"
                placeholder="选择设备厂家"
                :openDisabled="openDisabled"
              /> -->

              <treeselect v-model="form.pcjArray" :disable-branch-nodes="true" :options="dialogData" :limit="2"
                placeholder="选择设备厂家" :normalizer="normalizer2" :searchable="false" :appendToBody="false" multiple
                @select="addSelect" :disabled="openDisabled" collapse-tags />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="瓶盖厂商" prop="gcs">
              <!-- <el-input
                v-model="form.gcs"
                placeholder="请输入盖厂商"
                :disabled="openDisabled"
              /> -->
              <!-- <ReportDialog
                @dialogChange="form.gcs = $event.value"
                :echoValue="form.gcs"
                value="id"
                label="label"
                placeholder="选择设备厂家"
                :openDisabled="openDisabled"
              /> -->
              <treeselect v-model="form.gcjArray" :disable-branch-nodes="true" :options="dialogData" :limit="2"
                placeholder="选择设备厂家" :normalizer="normalizer2" :searchable="false" :appendToBody="false" multiple
                @select="addSelect" :disabled="openDisabled" collapse-tags />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
                <el-form-item label="检测项目" prop="jcxm">
                  <el-input v-model="form.jcxm" placeholder="请输入检测项目" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
          <!-- <el-col :span="12">
                <el-form-item label="品控员" prop="pky">
                  <el-input v-model="form.pky" placeholder="请输入品控员" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
          <!-- <el-col :span="12">
                <el-form-item label="报表编号" prop="bbbh">
                  <el-input v-model="form.bbbh" placeholder="请输入报表编号" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
          <!-- <el-col :span="12">
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" placeholder="请输入备注" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
        </el-row>
        <br />
        <el-divider content-position="center">瓶装水扭矩测试记录子信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddQualityProdTorqueSub"
              :disabled="openDisabled">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteQualityProdTorqueSub"
              :disabled="openDisabled">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="qualityProdTorqueSubList" :row-class-name="rowQualityProdTorqueSubIndex"
          @selection-change="handleQualityProdTorqueSubSelectionChange" ref="qualityProdTorqueSub" max-height="550">
          <el-table-column type="selection" width="50" align="center" />
          <!-- <el-table-column label="序号" align="center" prop="index" width="50"/> -->
          <!-- <el-table-column label="编号" prop="bh">
            <template slot-scope="scope">

              <el-select v-model="scope.row.bh" :disabled="openDisabled">
                <el-option value="1">1</el-option>
                <el-option value="2">2</el-option>
                <el-option value="3">3</el-option>
                <el-option value="4">4</el-option>
                <el-option value="5">5</el-option>
                <el-option value="6">6</el-option>
                <el-option value="7">7</el-option>
                <el-option value="8">8</el-option>
                <el-option value="9">9</el-option>
                <el-option value="10">10</el-option>
                <el-option value="11">11</el-option>
                <el-option value="12">12</el-option>
                <el-option value="13">13</el-option>
                <el-option value="14">14</el-option>
                <el-option value="15">15</el-option>
                <el-option value="16">16</el-option>
                <el-option value="17">17</el-option>
                <el-option value="18">18</el-option>
                <el-option value="19">19</el-option>
                <el-option value="20">20</el-option>
                <el-option value="21">21</el-option>
                <el-option value="22">22</el-option>
                <el-option value="23">23</el-option>
                <el-option value="24">24</el-option>
                <el-option value="25">25</el-option>
                <el-option value="26">26</el-option>
                <el-option value="27">27</el-option>
                <el-option value="28">28</el-option>
                <el-option value="29">29</el-option>
                <el-option value="30">30</el-option>
              </el-select>
            </template>
          </el-table-column> -->
          <el-table-column label="检测项目" prop="jcxm" min-width="260">
            <template slot-scope="scope">
              <!-- <el-input v-model="scope.row.jcxm" placeholder="请输入检测项目" :disabled="openDisabled"/> -->
              <el-select v-model="scope.row.jcxm" :disabled="openDisabled" @change="airtightness(scope)">
                <el-option value="开启扭矩">开启扭矩</el-option>
                <el-option value="断环扭矩">断环扭矩</el-option>
                <el-option value="净含量（mL）">净含量（mL）</el-option>
                <el-option value="密封性">密封性</el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="1" prop="a1">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a1"  :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a1" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="2" prop="a2">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a2" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a2" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>

          <el-table-column min-width="160" label="3" prop="a3">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a3" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a3" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="4" prop="a4">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a4" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a4" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="5" prop="a5">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a5" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a5" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="6" prop="a6">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a6" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a6" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="7" prop="a7">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a7" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a7" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="8" prop="a8">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a8" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a8" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="9" prop="a9">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a9" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a9" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="10" prop="a10">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a10" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a10" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="11" prop="a11">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a11" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a11" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="12" prop="a12">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a12" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input @input="input(scope,scope.row.jcxm)" :type="scope.row.jcxm=='密封性'?'text':'number'"
                v-model="scope.row.a12" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column min-width="160" label="平均值" prop="avg">
            <template slot-scope="scope">
              <!-- <el-select v-model="scope.row.a12" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select> -->
              <el-input v-model="scope.row.avg" placeholder="请输入" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="品控员" prop="pky" min-width="140">
            <template slot-scope="scope">
              <!-- <el-input
                v-model="scope.row.pky"
                placeholder="请输入品控员"
                :disabled="openDisabled"
              /> -->
              <UserDialog @dialogChange="scope.row.pky = $event.label" :echoValue="scope.row.pky" :multiple="false"
                :openDisabled="openDisabled" />
              <!--              <el-select-->
              <!--                v-model="scope.row.pky"-->
              <!--                filterable-->
              <!--                allow-create-->
              <!--                placeholder="请选择品控员"-->
              <!--                style="width: 100%"-->
              <!--                :disabled="openDisabled"-->
              <!--              >-->
              <!--                <el-option-->
              <!--                  v-for="item in userList"-->
              <!--                  :key="item.nickName"-->
              <!--                  :label="item.nickName"-->
              <!--                  :value="item.nickName"-->
              <!--                ></el-option>-->
              <!--              </el-select>-->
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="remark" width="180px">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark" placeholder="请输入备注" :disabled="openDisabled" type="textarea" />
            </template>
          </el-table-column>
        </el-table>

        <!-- 审核 -->
        <el-col :span="12">
          <el-form-item label="审核人" prop="shrperson">
            <el-input v-model="form.shrperson" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listTorque_main,
    getTorque_main,
    delTorque_main,
    addTorque_main,
    updateTorque_main,
    getPx,
    checkTorque_main,
  } from "@/api/quality/productionline/torque_main";
  import { getEqpfactoryName } from "@/api/basic/eqpfactory/eqpfactory";
  import { getInfo } from "@/api/login";
  import { listUser } from "@/api/system/user";
  import { listSelect2 } from "@/api/report/process/label";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  export default {
    name: "Torque_main",
    components: { Treeselect },
    data() {
      return {
        /* 当前用户名 */
        nickName: "",
        userList: [],
        //弹窗是否禁止编辑
        openDisabled: true,
        // 遮罩层
        loading: true,
        dialogData: [],
        ccpType: null,
        // 选中数组
        ids: [],
        // 子表选中数据
        checkedQualityProdTorqueSub: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        px: [],
        // 瓶装水扭矩测试记录表格数据
        torque_mainList: [],
        // 瓶装水扭矩测试记录子表格数据
        qualityProdTorqueSubList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 50,
          scpx: null,
          cssj: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
      };
    },
    created() {
      this.getListfac();
      this.getList();
      this.queryPx();
      this.queryUserList();
      this.getConfigKey("ccp_type").then((response) => {
        this.ccpType = response.msg;
        console.log(this.ccpType);
      });
    },
    methods: {
      /** 转换数据结构 */
      normalizer2(node) {
        if (node.children && !node.children.length) {
          delete node.children;
        }
        return {
          id: node.id,
          label: node.label,
          children: node.children,
        };
      },
      addSelect(value) {
        console.log(value);
        // this.selectList = value.label
      },
      getListfac() {
        listSelect2().then((response) => {
          this.dialogData = response.rows;
          // console.log(response.rows)
          // // console.log(this.dialogData);
          // /*        this.selectionLabel = this.findPathByLeafId(
          //   this.echoValue,
          //   this.tableData
          // );*/
        });
      },
      //输入框改变
      input(scope, val) {
        if (val != '密封性') {
          let number = 0
          for (let i = 1; i < 13; i++) {
            if (this.qualityProdTorqueSubList[scope.$index]['a' + i]) {
              number += Number(this.qualityProdTorqueSubList[scope.$index]['a' + i])
            }
          }
          this.qualityProdTorqueSubList[scope.$index].avg = (number / 12).toFixed(2)
        }
      },
      airtightness(scope) {
        if (scope.row.jcxm == "密封性") {
          for (let i = 1; i < 13; i++) {
            this.qualityProdTorqueSubList[scope.$index]['a' + i] = '正常'
          }
          this.qualityProdTorqueSubList[scope.$index].avg = '正常'
          // this.qualityProdTorqueSubList[scope.$index].a1 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a2 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a3 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a4 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a5 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a6 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a7 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a8 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a9 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a10 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a11 = "正常";
          // this.qualityProdTorqueSubList[scope.$index].a12 = "正常";
        } else {
          for (let i = 1; i < 13; i++) {
            this.qualityProdTorqueSubList[scope.$index]['a' + i] = ''
          }
          this.qualityProdTorqueSubList[scope.$index].avg = 0
        }
      },
      dialogChange(event, scope) {
        // this.reportSub2List[scope.$index].ypmc = event.options.code;
        this.form.scpx = event.label;
      },
      queryPx() {
        getPx().then((response) => {
          this.px = response.data;
          // console.log(response.data);
        });
      },
      // 查询工厂名称
      // queryFactory(row, column) {

      //   var temp_name= getEqpfactory(row.pcj).then((response) => {
      //     // temp_name = response.data.name;
      //   });
      //   console.log(temp_name)
      //   return temp_name;
      // },
      /** 查询瓶装水扭矩测试记录列表 */
      getList() {
        this.loading = true;
        listTorque_main(this.queryParams).then((response) => {
          this.torque_mainList = response.rows;
          this.total = response.total;
          getEqpfactoryName().then((response) => {
            var dt = response.data;
            // console.log(dt);
            for (let i = 0; i < this.torque_mainList.length; i++) {
              for (let j = 0; j < dt.length; j++) {
                if (this.torque_mainList[i].pcj == dt[j].id) {
                  this.torque_mainList[i].pcj = dt[j].name;
                }
                if (this.torque_mainList[i].gcs == dt[j].id) {
                  this.torque_mainList[i].gcs = dt[j].name;
                }
              }
            }
          });
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          syrq: null,
          scrq: null,
          scpx: null,
          cssj: null,
          pcj: null,
          gcs: null,
          jcxm: null,
          pky: null,
          shrperson: null,
          bbbh: "LK-QF-LS1-10-015-11-05",
          remark: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          delFlag: null,
        };
        this.qualityProdTorqueSubList = [];
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map((item) => item.id);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.openDisabled = false;
        this.open = true;
        this.title = "添加瓶装水扭矩测试记录";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.openDisabled = false;
        const id = row.id || this.ids;
        getTorque_main(id).then((response) => {
          this.form = response.data;
          this.qualityProdTorqueSubList = response.data.qualityProdTorqueSubList;

          this.open = true;
          this.title = "修改瓶装水扭矩测试记录";
          try {
            for (let index in this.qualityProdTorqueSubList) {
              if (this.qualityProdTorqueSubList[index].jcxm != '密封性') {
                let number = 0
                for (let i = 1; i < 13; i++) {
                  if (this.qualityProdTorqueSubList[index]['a' + i]) {
                    number += Number(this.qualityProdTorqueSubList[index]['a' + i])
                  }
                }
                this.qualityProdTorqueSubList[index].avg = (number / 12).toFixed(2)
              } else {
                this.qualityProdTorqueSubList[index].avg = '正常'
              }
            }
          } catch (error) {
            console.log(error)
          }
        });
      },
      /** 查看按钮 */
      handleView(row) {
        this.reset();
        this.openDisabled = true;
        const id = row.id || this.ids;
        getTorque_main(id).then((response) => {
          this.form = response.data;
          this.qualityProdTorqueSubList = response.data.qualityProdTorqueSubList;
          this.open = true;
          this.title = "查看瓶装水扭矩测试记录";
          try {
            for (let index in this.qualityProdTorqueSubList) {
              if (this.qualityProdTorqueSubList[index].jcxm != '密封性') {
                let number = 0
                for (let i = 1; i < 13; i++) {
                  if (this.qualityProdTorqueSubList[index]['a' + i]) {
                    number += Number(this.qualityProdTorqueSubList[index]['a' + i])
                  }
                }
                this.qualityProdTorqueSubList[index].avg = (number / 12).toFixed(2)
              } else {
                this.qualityProdTorqueSubList[index].avg = '正常'
              }
            }
          } catch (error) {
            console.log(error)
          }
        });
      },

      excelhandleView(row) {
        this.download(
          "Productionline/torque_main/exportexcel?id=" + row.id,
          {
            ...this.queryParams,
          },
          "瓶装水扭矩测试记录" + this.parseTime(new Date()) + ".xlsx"
        );
      },

      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            this.form.qualityProdTorqueSubList = this.qualityProdTorqueSubList;
            /**打开遮罩层*/
            const rLoading = this.openLoading();
            if (this.form.id != null) {
              updateTorque_main(this.form)
                .then((response) => {
                  /**成功后执行关闭遮罩层*/
                  rLoading.close();
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                })
                .catch((error) => {
                  /**请求异常后执行关闭遮罩层*/
                  rLoading.close();
                });
            } else {
              addTorque_main(this.form)
                .then((response) => {
                  /**成功后执行关闭遮罩层*/
                  rLoading.close();
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                })
                .catch((error) => {
                  /**请求异常后执行关闭遮罩层*/
                  rLoading.close();
                });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm(
          '是否确认删除瓶装水扭矩测试记录编号为"' + ids + '"的数据项?',
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(function () {
            return delTorque_main(ids);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          })
          .catch(() => { });
      },
      /** 瓶装水扭矩测试记录子序号 */
      rowQualityProdTorqueSubIndex({ row, rowIndex }) {
        row.index = rowIndex + 1;
      },
      /** 瓶装水扭矩测试记录子添加按钮操作 */
      handleAddQualityProdTorqueSub() {
        let obj = {};
        obj.bh = "";
        obj.pky = this.nickName;
        obj.a1 = "";
        obj.a2 = "";
        obj.jcxm = "";
        obj.a3 = "";
        obj.remark = "";
        obj.a4 = "";
        obj.a5 = "";
        obj.a6 = "";
        obj.a7 = "";
        obj.a8 = "";
        obj.a9 = "";
        obj.a10 = "";
        obj.a11 = "";
        obj.a12 = "";
        this.qualityProdTorqueSubList.push(obj);
      },
      /** 瓶装水扭矩测试记录子删除按钮操作 */
      handleDeleteQualityProdTorqueSub() {
        if (this.checkedQualityProdTorqueSub.length == 0) {
          this.$alert("请先选择要删除的瓶装水扭矩测试记录子数据", "提示", {
            confirmButtonText: "确定",
          });
        } else {
          this.qualityProdTorqueSubList.splice(
            this.checkedQualityProdTorqueSub[0].index - 1,
            1
          );
        }
      },
      /** 单选框选中数据 */
      handleQualityProdTorqueSubSelectionChange(selection) {
        if (selection.length > 1) {
          this.$refs.qualityProdTorqueSub.clearSelection();
          this.$refs.qualityProdTorqueSub.toggleRowSelection(selection.pop());
        } else {
          this.checkedQualityProdTorqueSub = selection;
        }
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(
          "Productionline_torque_main/torque_main/export",
          {
            ...this.queryParams,
          },
          "瓶装水扭矩测试记录" + this.parseTime(new Date()) + ".xlsx"
        );
      },
      //接收编号
      nameChange(e) {
        this.form.bbbh = e;
      },
      /** 审核按钮操作 */
      handleCheck(row) {
        /* 审核 */
        this.ids.forEach((id) => {
          getTorque_main(id).then((response) => {
            if (
              response.data.shrperson != null &&
              response.data.shrperson != ""
            ) {
              this.msgError(
                '编号为"' + id + '"的数据项已审核完成，无需重复审核！'
              );
            } else {
              let obj = {};
              obj.id = id;
              obj.shrperson = this.$store.state.user.nickName;

              obj.qualityProdTorqueSubList = this.qualityProdTorqueSubList;

              /* 修改 */
              checkTorque_main(obj).then((response) => {
                this.msgSuccess('编号为"' + id + '"的数据项审核成功！');
                this.getList();
              });
            }
          });
        });
      },
      /* 查询用户列表 */
      queryUserList() {
        listUser().then((response) => {
          this.userList = response.rows;
        });
        getInfo().then((response) => {
          this.nickName = response.user.nickName;
        });
      },
    },
  };
</script>